package ${package.Controller};

import org.springframework.web.bind.annotation.*;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import com.cnpc.eisc.base.pojo.PageInfo;
import com.cnpc.eisc.base.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
* ${moduleComment}
* @author ${author}
* @since ${date}
*/
<#if restControllerStyle>
@RestController
@Slf4j
<#else>
 @Controller
</#if>
@RequestMapping("/main/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
    class ${table.controllerName}<#if superControllerClass??>:${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>public class ${table.controllerName} extends ${superControllerClass}{
    <#else>public class ${table.controllerName} {
    </#if>

    @Autowired
    private ${table.serviceName} ${(table.serviceName?substring(1))?uncap_first};

    /**
    * ${table.comment!}_列表
    * @param pageNum 第几页，从0开始 默认0
    * @param pageSize 每页条数 默认10条
    * @param sortField 排序字段 数据库字段 默认create_time
    * @param isAsc 是否正序 默认false
    * @param ${entity?uncap_first} 搜索
    */
    @GetMapping(value="/page")
    public Result<PageInfo<${entity}>> queryPage(@RequestParam(required = false, defaultValue = "0") Integer pageNum,
                                        @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                        @RequestParam(required = false, defaultValue = "CREATE_DATE") String sortField,
                                        @RequestParam(required = false, defaultValue = "false") Boolean isAsc,
                                        ${entity} ${entity?uncap_first}){
        log.info("查询${table.comment!}列表入参，页码：{},每页条数：{},搜索参数{}", pageNum,pageSize,${entity?uncap_first});
        PageInfo<${entity}> pageInfo=new PageInfo();
        pageInfo.setPageSize(pageSize);
        pageInfo.setPageNum(pageNum);
        return Result.ok(${(table.serviceName?substring(1))?uncap_first}.query(pageInfo,sortField,isAsc,${entity?uncap_first}));
    }

    /**
    * ${table.comment!}_新增 或者 修改
    * @param ${entity?uncap_first}
    */
    @PostMapping(value="/add")
    public Result<Integer> add(@RequestBody ${entity} ${entity?uncap_first}){
        log.info("新增${table.comment!}入参：{}", ${entity?uncap_first});
        return Result.ok(${(table.serviceName?substring(1))?uncap_first}.add(${entity?uncap_first}));
    }

    /**
    * ${table.comment!}_批量删除
    * @param ids 主键id组
    */
    @PostMapping(value="/delete")
    public Result<Integer> delete(@RequestBody List<String> ids){
        log.info("删除${table.comment!}入参，主键ID组：{}", ids);
        return Result.ok(${(table.serviceName?substring(1))?uncap_first}.delete(ids));
    }

     /**
     * ${table.comment!}_详情
     * @param id 主键ID
     */
     @GetMapping("/detail")
     public Result<${entity}> detail(@RequestParam("id") String id){
        log.info("查询${table.comment!}详情入参，主键ID:{}", id);
        return Result.ok(${(table.serviceName?substring(1))?uncap_first}.detail(id));
     }
}
</#if>